package com.breakfast.fun.ui.user.feedback;

import com.breakfast.fun.data.entity.user.feedback.Feed;
import com.breakfast.fun.data.entity.user.feedback.FeedData;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/9/9.
 */
public class FeedBackPresenter extends FeedBackContract.Presenter {
    @Override
    public void submitFeed(FeedData feedData) {
        Map<String, String> map = Api.getInstance().getBaseParams();

        map.put("action", "feedback");
        map.put("content", feedData.getContent());
        map.put("name", feedData.getName());
        map.put("mobile", feedData.getMobile());

        showLoadingDialog(true);

        rxManager.add(model.getFeedModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<Feed>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        T.show("提交失败");
                    }

                    @Override
                    public void onNext(Feed feed) {
                        if (feed.isSuccess()) {
                            view.feedSuccess();
                        } else {
                            T.show(feed.getMsg());
                        }
                        hideLoadingDialog();
                    }

                }));
    }

    @Override
    public void onStart() {

    }
}
